package com.gyg.程序员面试金典;

import java.util.Arrays;

/**
 * 面试题 01.09. 字符串轮转
 */
public class T01_09 {
    public static void main(String[] args) {
        T01_09 t01_09 = new T01_09();
        boolean flipedString = t01_09.isFlipedString("waterbottle", "erbottlewat");
        System.out.println(flipedString);

    }
    /**
     * 面试题 01.09. 字符串轮转
     *
     * @param s1
     * @param s2
     * @return
     */
    public boolean isFlipedString(String s1, String s2) {
        if (s1.length() != s2.length()){
            System.out.println("输出");
            return false;
        }
        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        Arrays.sort(c1);
        Arrays.sort(c2);
        if (Arrays.toString(c1).equals(Arrays.toString(c2))){
            return true;
        }
        return false;
    }

    public boolean isFlipedString2(String s1, String s2) {
        if (s1.length() != s2.length()){
            System.out.println("输出");
            return false;
        }
//        将两个s1字符串相加，得到一个新的字符串，该串中间部分为s1的倒置
        String s3 = s1 + s1;
//        判断s3中是否包含s2
        return s3.contains(s2);
    }

}
